package forms;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import data.UserData;

import models.UserModel;

public class UserForm {
	public TreeMap checkValid(HttpServletRequest request, UserModel user) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		
		String fullname = (String) request.getParameter("fullname");
		String gender = (String) request.getParameter("gender");
		
		if (fullname == null || fullname.equals("")) {
			check.put("fullname", "Full name is not empty");
			user.setFullname(fullname);
		} else {
			user.setFullname(fullname);
		}
		
		if (gender != null) {
			try {
				user.setGender(Integer.parseInt(gender));
			} catch (Exception e) {
				check.put("gender", "Gender for user not valid!");
			}
		}
		
		form.put("checkValid", check);
		form.put("user", user);
		
		return form;
	}
}
